﻿using UnityEngine;
using System.Collections;

[AddComponentMenu("TagMachine/UI/Menu/Menu")]
public class UIMenu : MonoBehaviour
{
	private static UIMenu s_CurrentMenu = null;

	public bool StartsOpen 				= false;

	private Animator m_Animator			= null;

	// Use this for initialization
	void Awake ()
	{
		m_Animator 	= GetComponent< Animator >();
		m_Animator.SetBool( "IsOpen", StartsOpen );

		if ( StartsOpen )
		{
			if ( s_CurrentMenu != null )
			{
				Debug.LogWarning("Multiple menus starts open!!!");
			}

			s_CurrentMenu = this;
		}
	}

	public void OpenMenu()
	{
		if ( s_CurrentMenu != null )
		{
			s_CurrentMenu.CloseMenu();
		}

		m_Animator.SetBool( "IsOpen", true );

		s_CurrentMenu = this;
	}

	public void CloseMenu()
	{
		if ( s_CurrentMenu == this )
		{
			s_CurrentMenu = null;
		}

		m_Animator.SetBool( "IsOpen", false );
	}
}
